package com.xinghou.platform.server.api.bussiness.impl;

import com.xinghou.platform.dao.main.AreaCodeDAO;
import com.xinghou.platform.model.main.AreaCode;
import com.xinghou.platform.server.api.bussiness.AreaService;
import com.xinghou.platform.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by qingshengzheng on 16/7/4.
 */
@Service("areaService")
public class AreaServiceImpl implements AreaService {
    @Resource
    private AreaCodeDAO areaCodeDAO;
    @Override
    public String[] getAreaCodeForApp(String adcode) {
        if(StringUtils.isEmpty(adcode))
            return null;
        AreaCode areaCode=areaCodeDAO.queryByAdcode(adcode);
        if(areaCode==null) return null;
        String[] v=new String[2];
        v[0]=adcode;
        if(areaCode.getLevel().equals("district"))
                v[1]=areaCode.getCity()+(StringUtils.isBlank(areaCode.getDistrict())?"":"-"+areaCode.getDistrict());
            else
                v[1]=areaCode.getProvince()+(StringUtils.isBlank(areaCode.getCity())?"":"-"+areaCode.getCity());
        return v;
    }
}
